package com.heima.article.controller;

import com.heima.article.entity.ApAuthor;
import com.heima.common.dto.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.heima.article.service.IApAuthorService;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP文章作者信息表 前端控制器
 * </p>
 *
 * @author lqw
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/api/v1/author")
@Api(tags = "APP文章作者信息表接口")
public class ApAuthorController{

    @Autowired
    private IApAuthorService apAuthorService;

    /**
     * 新增作者
     * @param author
     * @return
     */
    @PostMapping
    public ResponseResult<ApAuthor> saveApAuthor(@RequestBody ApAuthor author) {
        return apAuthorService.saveApAuthor(author);
    }

    /**
     * 根据id查询作者
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<ApAuthor> getAuthorById(@PathVariable Integer id){
        ApAuthor author = apAuthorService.getById(id);
        return ResponseResult.okResult(author);
    }

}
